package com.wxh.utils;


import org.apache.commons.codec.binary.Base64;

/**
 * @ClassName: Base64CodeUtils
 * @Description: base64编码解码
 * @Author wxh
 * @Date: 2020/7/27 10:00
 * @Version V1.0.0
 * @Since 1.8
 */
public final class Base64CodeUtils {

    private Base64CodeUtils(){

    }

    public static void main(String[] args) {
        String str = "wxhaa123";
        // 编码
        String encodeStr = encode(str.getBytes());
        System.out.println(str + " 编码后的字符串为：" + encodeStr);
        // 解码
        String decodeStr = decode(encodeStr.getBytes());
        System.out.println(encodeStr + " 字符串解码后为：" + decodeStr);
    }

    /**
     *  编码将字节数组转换为字符串
     * @param bytes 字节数组
     * @return String
     */
    public static String encode(byte[] bytes){
        return new String(Base64.encodeBase64(bytes));
    }

    /**
     * 解码将字节数组转换为字符串
     * @param bytes 字节数组
     * @return String
     */
    public static String decode(byte[] bytes){
        return new String(Base64.decodeBase64(bytes));
    }


}
